<template>
  <nav-bar class="nav-bar">
    <div slot="left" @click="callBack">
      <img src="@/assets/img/common/back.svg" />
    </div>
    <div slot="center" class="title">
      <div
        v-for="(title, index) in titles"
        :key="index"
        class="title-item"
        :class="{ active: index === currentTitle }"
        @click="titleClick(index)">
        {{ title }}
      </div>
    </div>
  </nav-bar>
</template>

<script>
import NavBar from "@/components/common/navbar/NavBar";
export default {
  components: {
    NavBar,
  },
  data() {
    return {
      titles: ["商品", "参数", "评论", "推荐"],
      currentTitle: 0,
    };
  },
  methods: {
    titleClick(index) {
      this.currentTitle = index;
      this.$emit("titleClick", index)
    },
    callBack() {
      this.$router.go(-1);
    },
  },
};
</script>

<style scoped>
.nav-bar {
  background-color: #fff;
  line-height: 44px;
}
.nav-bar img {
  margin-top: 12px;
}
.title {
  display: flex;
  padding: 0 10px;
}
.title-item {
  flex: 1;
  font-size: 13px;
}
.active {
  color: red;
}
</style>
